package com.csi.controller.role;

import com.alibaba.fastjson2.JSON;
import com.csi.domain.Employee;
import com.csi.domain.Role;
import com.csi.pojo.Result;
import com.csi.service.EmployeeService;
import com.csi.service.PermissionService;
import com.csi.service.RoleService;
import com.csi.service.impl.EmployeeServiceImpl;
import com.csi.service.impl.PermissionServiceImpl;
import com.csi.service.impl.RoleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@WebServlet("/role/findAllController")
public class FindAllController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Result<Map<String, Role>> result = new Result<>();

        RoleService roleService = new RoleServiceImpl();

        Map<String, Role> roleList = roleService.findAll();

        if (roleList != null) {
            result.setCode(200);
            result.setMsg("success");
            result.setDatas(roleList);
        } else {
            result.setCode(400);
            result.setMsg("false");
        }
        out.print(JSON.toJSONString(result));
        out.flush();
        out.close();
    }
}
